<script>
import { User, View } from "@element-plus/icons";
export default {
  name: "login",
  data() {
    return {
      user: {
        userName: "",
        userPwd: "",
      },
      rules: {
        userName: [
          { required: true, message: "请输入用户名", trigger: "blur" },
        ],
        userPwd: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    login() {
      this.$refs.userForm.validate((res) => {
        if (res) {
          this.$api.login(this.user).then((res) => {
            console.log(res);
            this.$store.commit("saveUserInfo", res);
            this.$router.push("/welcome");
          });
        }
      });
    },
  },
  computed: {
    users() {
      return User;
    },
    view() {
      return View;
    },
  },
  mounted() {
    //     this.$request({
    // url:'/login',
    // method:'get',
    // data:{
    //     name: "admin",
    // }
    // }).then(res=>{
    //     console.log(res)
    // })
    // this.$storage.setItem("user",{name:"张三",age:18})
  },
};
</script>

<template>
  <div class="loginBody">
    <div class="login">
      <el-form class="elform" :model="user" :rules="rules" ref="userForm">
        <div class="login-title">登录</div>
        <el-form-item label="用户名:" prop="userName">
          <el-input
            type="text"
            placeholder="请输入用户名"
            v-model="user.userName"
          ></el-input>
        </el-form-item>
        <el-form-item label=" 密码:" prop="userPwd">
          <el-input
            type="password"
            placeholder="请输入密码"
            v-model="user.userPwd"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<style scoped lang="scss">
.loginBody {
  width: 100%;
  height: 100vh;
  background-color: #dfdfdf;
  display: flex;
  justify-content: center;
  align-items: center;

  .login {
    width: 400px;
    height: 300px;
    background-color: #fff;
    border-radius: 15px;
    .elform {
      // height: 100%;
      display: flex;
      flex-direction: column;
      padding: 40px;
      .el-form-item {
        height: 40px;
        display: flex;
        align-items: center;
      }
      .login-title {
        font-size: 24px;
        font-weight: 500px;
        color: #000;
        margin-bottom: 10px;
      }
    }
  }
}
</style>
